<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //利用结构化赋值交换两个变量的值
        let x = 1;
        let y =2;
        [x,y] = [y,x];
        console.log(x,y);

        //解构返回多个值
        function exzaple(){
            return [1,2,3];
        }
        let [a,b,c] = exzaple();
        console.log(a,b,c);
        // 嵌套结构
        let [e, [[f], g]] = [1, [[2], 3]]; 
        console.log(e,f,g);
        // 对象结构
        let {name,age} = {name:'张三',age:18};
        console.log(name,age);
        let {zhou,biwen} = { zhou:'周',biwen:'比文'};
        console.log(zhou,biwen);

        const tmpl = addrs => `
            <table>
            ${addrs.map(addr => `
                <tr><td>${addr.first}</td></tr>
                <tr><td>${addr.last}</td></tr>
            `).join('')}
            </table>
            `;
         
        const data = [
            {first: 'aaa', last: 'bbb'},
            {first: 'ccc', last: 'ddd'}
        ];
        console.log(tmpl(data));
       

        //应用模板字符串本身，在需要时执行
        let func = (name)  => `hello ${name}!`;
        console.log(func('zhoubiwen'));
        


        
    </script>
</body>
</html>